﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlServerDataTableToExcel.BLL
{
    public  class FrmFuc
    {
        private IDAL.ISqlFuc  SqlFuc;

        public FrmFuc(string Type)
        {
            if (Type == Model.DataTypeEnum.SqlServer.ToString())
            {
                SqlFuc = new DAL.SqlServer();
            }
            if (Type == Model.DataTypeEnum.MySql.ToString())
            {
                SqlFuc = new DAL.MySql();
            }
        }

        /// <summary>
        /// 得到表结构的配置
        /// </summary>
        /// <returns></returns>
        public  List<Model.DataTableMsg> GetDataTableList(string IPAddress, string DataSource, string UserName, string Pwd)
        {
          return  SqlFuc.GetTableMsg( IPAddress,  DataSource,  UserName,  Pwd);
        }

        /// <summary>
        /// 导出Excel
        /// </summary>
        public  void ImportExcel(Model.Item_Model itemMsg)
        {
            List<Model.DataTableMsg> DtMsg = GetDataTableList(itemMsg.IpAddress, itemMsg.DataSource, itemMsg.Ds_Name, itemMsg.Ds_Pwd);
            Excel.ExportToExcel(DtMsg, itemMsg.FileName);
        }

        /// <summary>
        /// 得到目标数据库的所有数据库
        /// </summary>
        /// <returns></returns>
        public  List<string> GetDataSourceList(string IpAddress,string UserName,string UserPwd)
        {
            return SqlFuc.GetDataSourceList( IpAddress,  UserName,  UserPwd);
        }


    }
}
